package com.example.gymmanagebackend.mapper;

import com.example.gymmanagebackend.pojo.CoachReservation;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Date;
import java.util.List;

@Mapper
public interface CoachReservationMapper {
    @Insert("INSERT INTO CoachReservation (coach_id, coachName, username, reservationTime, reservation_date) VALUES (#{coachId}, #{coachName}, #{username}, #{reservationTime}, #{reservationDate})")
    @Options(useGeneratedKeys = true, keyProperty = "reservationId")
    int addCoachReservation(CoachReservation reservation);


    @Select("SELECT * FROM CoachReservation WHERE username = #{username}")
    List<CoachReservation> getCoachReservationsByUsername(String username);

    @Delete("DELETE FROM CoachReservation WHERE coachName = #{coachName} AND reservationTime = #{reservationTime}")
    int deleteCoachReservationByCondition(@Param("coachName") String coachName, @Param("reservationTime") String reservationTime);
    @Select("SELECT COUNT(*) FROM CoachReservation WHERE username = #{username} AND coachName = #{coachName} AND reservationTime = #{reservationTime} AND reservation_date = #{reservationDate}")
    int checkCoachReservationExists(@Param("username") String username, @Param("coachName") String coachName, @Param("reservationTime") String reservationTime, @Param("reservationDate") Date reservationDate);
    @Select("SELECT * FROM CoachReservation WHERE coach_id IS NOT NULL")
    List<CoachReservation> getAllCoachReservations();

    @Select("SELECT coachName, COUNT(*) AS count FROM CoachReservation GROUP BY coachName")
    List<CoachReservation> getCoachReservationCount();

    @Select("SELECT cr.coachName, m.gender, COUNT(*) AS count FROM CoachReservation cr JOIN Members m ON cr.username = m.name GROUP BY cr.coachName, m.gender")
    List<CoachReservation> getCoachGenderDistribution();

}
